package com.edu.api.entity.common;

/**
 * @Author:
 * @Description: 返回码定义
 * 规定:
 * #1表示成功
 * #1001～1999 区间表示参数错误
 * #2001～2999 区间表示用户错误
 * #3001～3999 区间表示接口异常
 * @Date Create in
 */
public enum ResultCode {
    /* 成功 */
    SUCCESS(200, "操作成功"),

    /* 默认失败 */
    COMMON_FAIL(500, "操作失败"),

    /* 令牌失效 */
    TOKEN_EXPIRATION(1000, "令牌失效"),

    /* 参数错误：1000～1999 */
    PARAM_NOT_VALID(1001, "参数无效"),
    PARAM_IS_BLANK(1002, "参数为空"),
    PARAM_TYPE_ERROR(1003, "参数类型错误"),
    PARAM_NOT_COMPLETE(1004, "参数缺失"),

    /*菜单错误*/
    MENU_DUPLICATE(5000, "菜单名称重复"),
    MENU_DUPLICATE_ROUTING_ADDRESS(5001, "路由地址重复"),
    MENU_DUPLICATE_COMPONENT_PATH(5002, "组件路劲重复"),
    MENU_REPEAT(5003, "菜单名、路由地址或组件路劲重复"),
    FILE_MENU(5004, "不能修改到同菜单及其子菜单"),
    FILE_MENUTYPE(5005, "有子菜单不能修改为按钮"),
    NO_MENU_UNDER_BUTTON(5006,"按钮下不能有子集"),

    /*字典错误*/
    DICT_DUPLICATE_LABEL(4001, "字典标签重复"),
    DICT_DUPLICATE_VALUE(4002, "字典键值重复"),
    DICT_DUPLICATE_SORT(4003, "字典排序重复"),
    DICT_DUPLICATE_DICTIONARY_NAME(4004, "字典名称重复"),
    DICT_DUPLICATE_DICTIONARY_TYPE(4005, "字典类型重复"),
    DICT_DUPLICATE_HAVE_DATA(4006, "该字典下还有数据，不能删除"),
    DICT_DEACTIVATION(4007, "父级字典停用，不能修改"),

    /*角色错误*/
    ROLE_DUPLICATE(1009, "角色名称重复"),
    ROLE_DUPLICATE_ROUTING_ADDRESS(1010, "角色修改有误，请联系管理员"),
    ROLE_DUPLICATE_STATUS_PATH(1011, "角色状态修改失败"),
    ROLE_REPEAT(1012, "角色名、路由地址或组件路径重复"),
    ROLE_CONT_DELETE_YOURSELF(1013, "不能删除本身"),
    ROLE_CONT_DELETE(1014, "权限不足"),

    /*岗位错误*/
    ROLE_CONT_DELETE_POST(1015, "该岗位下有用户不能删除"),
    ROLE_CONT_DELETE_POST_STATUS(1016, "该岗位下有用户不能修改状态"),
    POST_CONT_INSERT_CODE(1020, "岗位编码不能重复"),
    POST_CONT_INSERT_NAME(1020, "岗位名称不能重复"),
    POST_CONT_INSERT_STATUS(1021, "岗位下有用户不能修改"),

    /*部门错误*/
    DEPT_CONT_DELETE(2015, "删除失败，该部门下还有其他部门"),
    DEPT_ADD_FAILED(2016, "部门添加失败"),
    DEPT_ACCOUNT_ALREADY_EXIST(2017, "该同级下的部门已存在"),
    DEPT_EXIST(2018, "该部门不能是该部门的子部门"),
    DEPT_DUPLICATE_ROUTING_ADDRESS(2019, "部门修改有误，请联系管理员"),
    DEPT_USER_DELETE(2020, "删除失败，该部门下还有其他用户"),
    DEPT_ADD_FAILED_USER(2016, "该父级部门已经停用"),

    /* 用户错误 */
    USER_NOT_LOGIN(2001, "用户未登录"),
    USER_ACCOUNT_EXPIRED(2002, "添加成功"),
    USER_CREDENTIALS_ERROR(2003, "旧密码错误"),
    USER_CREDENTIALS_EXPIRED(2004, "密码过期"),
    USER_ACCOUNT_DISABLE(2005, "账号不可用"),
    USER_ACCOUNT_LOCKED(2006, "账号被停用"),
    USER_ACCOUNT_NOT_EXIST(2007, "用户不存在/密码错误"),
    USER_ACCOUNT_ALREADY_EXIST(2008, "账号已存在"),
    USER_ACCOUNT_USE_BY_OTHERS(2009, "账号下线"),
    USER_CONT_DELETE(2010, "管理员不能被删除"),
    USER_DELETE(2011, "账号已被删除"),
    USER_ACCOUNT_NAME(2050, "用户昵称不能重复"),
    USER_ACCOUNT_CALL(2051, "电话号码不能重复"),
    USER_ACCOUNT_EMAIL(2052, "邮箱不能重复"),
    USER_ACCOUNT_SEX(2053, "性别不能为空"),
    USER_ACCOUNT_PHONENUMBER(2055, "手机号不能为空"),
    USER_ACCOUNT_EMAIL_NULL(2056, "邮箱不能为空"),
    USER_ACCOUNT_NICKNAME(2054, "用户昵称重复"),
    USER_YES_LOGIN(200, "登录成功"),
    USER_IDENTITY (2055, "身份证格式错误"),
    /* 业务错误 */
    NO_PERMISSION(3001, "没有权限"),

    /* 房屋错误 */
    ROOM_DELETE(4101, "房屋删除失败"),
    ROOM_INSERT_FAILED(4102, "房屋添加失败"),
    ROOM_DUPLICATE_ROUTING(4103, "房屋修改有误，请联系管理员"),
    ROOM_ACCOUNT_ALREADY_EXIST(4104, "该单元下的房屋名称已存在"),
    ROOM_NOACCOUNT_ALREADY_EXIST(4105, "必须选择含单元的楼栋"),
    ROOM_CLOOSE(4106, "未选择报修房屋，不能报修"),

    /* 社区资产 */
    COMMUNITY_BUILDING_NAME(6000, "楼栋名称不能重复"),
    COMMUNITY_UNIT(6001, "楼栋下面有单元"),

    /* 小区错误 (6021~6040)*/
    BUILDING_UNDER_COMMUNITY(6021, "该小区下有楼栋"),
    COMMUNITY_ACCOUNT_COMMUNITY_NAME(6022, "该地区小区名重复"),

    /* 单元错误（6050~6070）*/
    UNIT_NAMES_CANNOT_BE_CONSISTENT(6050,"单元名称不能重复"),
    UNIT_NUMBER_CANNOT_BE_CONSISTENT(6051,"单元编号不能重复"),
    UNIT_NUMBER_CANNOT_BE_ZOOM(6052,"单元下有房屋不能删除"),

    /* 业主错误(6070-6090) */
    OWNER_ACCOUNT_CARD(6071, "用户身份证不能重复"),
    OWNER_ROOM_CONSISTENT(6072, "请勿重复提交"),
    OWNER_CONT_SUGGEST(6073,"业主已被禁用，不能投诉或建议"),
    NO_INTRODUCE(6074,"个人信息不全"),
    NO_ROOM(6075,"您名下没有绑定房产，不能投诉/建议"),
    NO_ROOM_TOW(6076,"您名下没有绑定房产，不能进行操作"),
    OWNER_ROOM_CONSISTENT_NUM(6077, "因为业务问题，一位业主只能绑定一间房屋，请勿重复提交绑定"),
    OWNER_ROOM_CONSISTENT_ALL(6078, "您的申请已提交，请勿重复提交"),
    OWNER_ROOM_CONSISTENT_NUMS(6079, "请把当前的申请房屋记录删除，再绑定房屋"),
    OWNER_ROOM_CONSISTENT_FAILED(6080, "房屋绑定操作失败"),
    OWNER_ACCOUNT_PhoneNumber(6081, "用户电话不能重复"),

    /* 车位错误(7000-7020)*/
    NO_INTRODUCES(7002,"实名认证不全，无法绑定车位"),
    NO_INTRODUCE_BINDING(7003,"个人信息不全，无法绑定车位"),
    PARKING_NOTBUY(7000,"租户不能购买车位"),
    PARKING_USED(7005,"该车位已被绑定"),
    PARKING_NOT(7001,"未选择车位，不能绑定"),
    NOT_DELETE(7001,"车位已绑定或审核中，不能删除");

    private Integer code;
    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 根据code获取message
     *
     * @param code
     * @return
     */
    public static String getMessageByCode(Integer code) {
        for (ResultCode ele : values()) {
            if (ele.getCode().equals(code)) {
                return ele.getMessage();
            }
        }
        return null;
    }
}
